package dispatcher.gui.menu;

import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.event.MenuEvent;
import javax.swing.event.MenuListener;

import dispatcher.gui.GroupDispatcherView;

/**
 * This class is used for enabling and disabling the kill all elevators menu item depending on the number of
 * elevators in the system
 * @author Caleb
 *
 */
public class GroupDispatcherViewElevatorMenuListener implements MenuListener {

	private JMenuItem item;
	
	/**
	 * The main constructor
	 * @param killAllItem The kill all elevators menu item
	 */
	public GroupDispatcherViewElevatorMenuListener(JMenuItem killAllItem){
		this.item = killAllItem;
	}
	
	@Override
	public void menuSelected(MenuEvent e)  {
		if (e.getSource() instanceof JMenu){
			
			JMenu menu = (JMenu)e.getSource();
			// If the number of the elevators in the system is greater then 0, enable the button
			if (menu.getText().equals("Elevators")){
				if (GroupDispatcherView.getInstance().getElevatorNumbers() <= 0){
					this.item.setEnabled(false);
				}else{
					this.item.setEnabled(true);
				}
			}
		}
	}

	@Override
	public void menuCanceled(MenuEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void menuDeselected(MenuEvent e) {
		// TODO Auto-generated method stub
		
	}

}
